Skip to content

tests: Stabilize screenshot tests and clean up flaky infrastructure#1220

Open
jderochervlk wants to merge 6 commits intomasterfrom
vlk/disable-animations
Open

tests: Stabilize screenshot tests and clean up flaky infrastructure#1220
jderochervlk wants to merge 6 commits intomasterfrom
vlk/disable-animations

Conversation

@jderochervlk
Copy link
Copy Markdown
Collaborator

@jderochervlk jderochervlk commented Apr 2, 2026

Fixes several issues with screenshot tests producing inconsistent or incorrect results.

I was getting different results running the tests locally versus the runs on CI, so I made some config changes to lock in the browser size and viewport. There were also some other issues I addressed to produce better and more stable results.

Key changes:**

  1. Removed ~60 stale/flaky screenshot baselines - The bulk of this PR deletes a large number of .png screenshot files from __tests__/__screenshots__/ across many test suites (Button, CodeExample, Blog, DocsLayout, Footer, SyntaxLookup, SidebarLayout, etc.). These were presumably unreliable or no longer needed.

  2. Stabilized screenshot comparison config (vitest.config.mjs) - Added explicit screenshot configuration:

    • Forces deviceScaleFactor: 1 to prevent DPI-related differences across machines
    • Sets scale: "css" for screenshot options
    • Adds tolerance thresholds (threshold: 0.2, allowedMismatchedPixelRatio: 0.05) to reduce false negatives
    • Disables the browser UI (ui: false)
  3. Added test-specific CSS overrides (styles/test-overrides.css) - A new stylesheet imported only in vitest.setup.mjs that:

    • Disables all CSS animations and transitions (zero duration/delay) to eliminate timing-based flakiness
    • Hides scrollbars (scrollbar-width: none) so scrollbar rendering differences across environments don't break screenshots
  4. Fixed NavbarSecondary tests - Switched from <BrowserRouter> to <MemoryRouter initialEntries=["/docs/manual/introduction"]>, giving the tests a deterministic URL context rather than relying on the browser's actual location.

  5. Removed video screenshot assertion - In MarkdownComponents_.test.res, the toMatchScreenshot("markdown-video") call was removed (video rendering is inherently non-deterministic for screenshots).

  6. Removed auto-commit of screenshots from CI (.github/workflows/pull-request.yml) - The git-auto-commit-action step that automatically committed updated screenshots on PRs was removed, preventing confusing auto-pushed changes in PRs.

  7. Updated AGENTS.md - Added a rule clarifying that .jsx files should never be edited directly since they're compiler-generated by ReScript.

Overall: This is a testing infrastructure cleanup focused on making screenshot tests reliable and deterministic across different environments (local dev, CI, headless vs headed browsers) by eliminating the most common sources of visual diff noise.

run: yarn playwright install --with-deps
- name: Vitest
run: yarn ci:test
- name: Commit and Push changes
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a patch to keep the files in sync across local runs and CI to make sure that the CI versions were always used so they would be the same, but now they are the same in headless mode as they are running on chrome so this isn't needed.

Updates the Markdown image caption test to use a new caption and image.
Regenerates all related test screenshots to reflect the change.
Add detailed instructions for running and updating Vitest
browser-based unit tests in the README. Remove outdated
screenshot baseline PNGs from __tests__/__screenshots__.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Cloudflare deployment

Deployement ID: 288934cf-ac6f-4509-a062-c716bedba4e4
Deployment Environment: preview

⛅️ wrangler 4.63.0 (update available 4.80.0)
─────────────────────────────────────────────
✨ Compiled Worker successfully
Uploading... (7651/7653)
Uploading... (7652/7653)
Uploading... (7653/7653)
✨ Success! Uploaded 2 files (7651 already uploaded) (1.90 sec)

✨ Uploading _redirects
✨ Uploading Functions bundle
🌎 Deploying...
✨ Deployment complete! Take a peek over at https://288934cf.rescript-lang.pages.dev
✨ Deployment alias URL: https://vlk-disable-animations.rescript-lang.pages.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant